import os

from django.http import  HttpResponse
from django.shortcuts import render

from _exam .settings import BASE_DIR

def into(request):
    #获取表单中传过来的值
    image=request.FILES.get('img')
    sname=request.POST.get('name')
    province=request.POST.get('procince')
    kuqi=request.POST.get('kuqi')
    antu=request.POST.get('antu')
    sex=request.POST.get('sex')
    ruihander=request.POST.get('ruihander')

    #获取上传的图片
    try:
        with open(os.path.join(BASE_DIR,'book','static','img','image.name'),'wb')as f:
            for chunk in image.chunks():
                f.write(chunk)
    except Exception as f:
        return HttpResponse('修改失败请重新输入')

    print(sname,province,kuqi,antu,sex,ruihander)
    #响应并返回into.html界面
    return render(request,'into.html')

def all_user(request):
    users=[
        {"name": "张三", "address": "北京", "phone": "13543434233"},
        {"name": "李四", "address": "上海", "phone": "18843434233"},
        {"name": "王五", "address": "广州", "phone": "16643434233"}]
    #返回index界面并把users的数据传到index中并展示
    return render(request,'index.html',{'users':users})

def get_key(request):
    try:
        ie=request.GET.get('ie')
        wd=request.GET.get('wd')
    except Exception as s:
        return HttpResponse('没有获取到参数')
    #返回url中参数的值
    return HttpResponse(f'字符:{ie} 关键字:{wd}')

# Create your views here.
